<?php
ini_set('display_errors', 1);
set_time_limit(0);
include_once dirname(dirname(dirname(__FILE__))) . '/mgtv_init.php';
define('ORG_ID', 'dxjd');
include_once dirname(dirname(dirname(__FILE__))) . '/'.ORG_ID.'/init.php';

class cdn_index_execute extends nn_timer
{

    public function action($params = null)
    {
        $this->msg('开始执行...');
        do_timer_action();
        $this->msg('执行结束...');
    }
}
$cdn_index_execute = new cdn_index_execute("cdn_index_execute", ORG_ID);
$cdn_index_execute->run();

function do_timer_action()
{
    //从任务表取内容，调用C2执行
    i_echo('start');
    $sp_config = sp_model::get_sp_config(ORG_ID);
    if (isset($sp_config['disabled_cdn']) && (int)$sp_config['disabled_cdn'] === 1) {
        i_echo('close cdn');
    } else {
    
        //查询cdn多少分钟执行一次
        /**
         * ini 文件
         * start_time:  12345678
         * is_complete: 1,完成   0 没有完成
         *
         *
         */
        $crond_cdn_minute = $sp_config['crond_cdn_minute'];
        $minute = date('i');
        $star_time = time();
        $bool = false;
    
        if ( (int)($minute % $crond_cdn_minute) ==0 ) {
            //如果存在这个文件
            /*if (file_exists('crond_cdn_minute.ini')) {
             $config = parse_ini_file('crond_cdn_minute.ini');
             	
             print_r($config);die;
    
             if ((int)$config['is_complete'] === 1) {
             $bool = true;
             } else {
             if ($star_time - $config['start_time'] > 1800) {
             $bool = true;
             } else {
             $bool = false;
             }
             }
             } else {
             $bool = true;
             }*/
            $bool = true;
        }
        if ($bool === true) {
            //$ini_file = 'start_time='.$star_time.PHP_EOL;
            $re = content_task_model::vod($new_id_c2 = null, 'index', ORG_ID);
            //if($re){
            //	$ini_file .= 'is_complete=1'.PHP_EOL;
            //}else{
            //	$ini_file .= 'is_complete=0'.PHP_EOL;
            //}
            //$filename_init = 'crond_cdn_minute.ini';
            //$file_path_init = dirname(__FILE__).'/';
            //if(!is_dir($file_path_init)) mkdir($file_path_init,0777,true);
            //$file_path_init .= $filename_init;
            //file_put_contents($file_path_init,$ini_file);
        }
        i_echo('end');
    }
}